const commoneUrl = "http://127.0.0.1:9000";

let authInfoString =uni.getStorageSync("authInfo");
let authInfo=JSON.parse(authInfoString);
//get请求封装
function getRequest(url, data) {
  var promise = new Promise((resolve, reject) => {
    var postData = data;
    uni.request({
      url: commoneUrl + url,
      data: postData,
      method: "GET",
      dataType: 'json',
      header: {
        'content-type': 'application/json',
        'auth': authInfo.token || ''
      },
      success: function(res) {
        if (res.statusCode === 200) {
          resolve(res.data);
        } else {
          resolve(res.data)
        }
      },
      error: function(e) {
        reject('网络出错');
      }
    });
  });
  return promise;
}
//post请求封装
function postRequest(url, data) {
  var promise = new Promise((resolve, reject) => {
    var postData = data;
    uni.request({
      url: commoneUrl + url,
      data: postData,
      method: 'POST',

      header: {
        'content-type': 'application/json',
       'auth': authInfo.token || ''
      },
      success: function(res) {
        if (res.code === 200 && res.code == 0) {
          resolve(res.data);
        } else {
          resolve(res.data)
        }
      },
      error: function(e) {
        reject('网络出错');
      }
    })
  });
  return promise;
}
export default{
  postRequest,
  getRequest
}
